<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<style type="text/css">
.ui-datepicker {
   font-size: 13px;
   width: 180px;
}
.ui-datepicker select.ui-datepicker-month {
   width: 30%;
   font-size: 11px;
}
.ui-datepicker select.ui-datepicker-year {
   width: 40%;
   font-size: 11px;
}
</style>
<script>
$(function(){
   $("#showingDelete").click(function(){
      var showingNo =  $(":radio[name=showingCheckBtn]:checked").val();
      
      if(confirm("삭제하시겠습니까?")==false){
         return;
      }
      location.href="${initParam.root}admin/showing_delete.do?showingNo="+showingNo+"&movieNo=${requestScope.allInfoMap.movieContent.movieNo }";
   });
   $("#schedule").click(function(){
      var showingNo =  $(":radio[name=showingCheckBtn]:checked").val();
      var flag = false;
      $(":radio[name=showingCheckBtn]:checked").each(function(index,data){
         if(data.checked){
            flag=true;            
            return;
         }         
      });   
      if(flag==false){
         alert("상영정보를 선택해 주세요!");
         return;
      }
      location.href="${initParam.root}admin/schedule.do?showingNo="+showingNo;
   });
   var startM;
   var startD;
   $("#startDatepicker").datepicker({
       dateFormat:'yy.mm.dd',
       startDate:new Date(),
       /* minDate:'2014-11-20', // 날짜 선택 최소값
       maxDate:'2014-11-26', // 날짜 선택 최대값 */
       selectOtherMonths:true, // 다른 달 선택가능
       dayNames: ['월요일', '화요일', '수요일', '목요일', '금요일', '토요일', '일요일'],
        dayNamesMin: ['월', '화', '수', '목', '금', '토', '일'], 
        monthNamesShort: ['1','2','3','4','5','6','7','8','9','10','11','12'],
        monthNames: ['1월','2월','3월','4월','5월','6월','7월','8월','9월','10월','11월','12월'],
      onSelect:function(dateText, inst){
         var dateArr = dateText.split(".");
         startM=dateArr[1];
         startD=dateArr[2];
      }
    });
   var endM;
   var endD;
   $("#endDatepicker").datepicker({
       dateFormat:'yy.mm.dd',
       startDate:'2014.11.23',
       selectOtherMonths:true, // 다른 달 선택가능
       dayNames: ['월요일', '화요일', '수요일', '목요일', '금요일', '토요일', '일요일'],
        dayNamesMin: ['월', '화', '수', '목', '금', '토', '일'], 
        monthNamesShort: ['1','2','3','4','5','6','7','8','9','10','11','12'],
        monthNames: ['1월','2월','3월','4월','5월','6월','7월','8월','9월','10월','11월','12월'],
        onSelect:function(dateText, inst){
         var dateArr = dateText.split(".");
         endM=dateArr[1];
         endD=dateArr[2];
      }
    });
   $("#cinemaSelect").change(function(){
      $.ajax({
         type:"post",
         url:"${initParam.root}admin/checkCinema.do",
         data:"cinemaNo="+$(this).val()+"&movieNo=${requestScope.allInfoMap.movieContent.movieNo }",
         success:function(jsonData){
            if(jsonData==true){
               alert("상영 리스트에 선택한 영화관이 존재합니다!");
               $("form[name=writeShowingForm]")[0].reset();
            }
         }
      });
   });
   $("form[name=writeShowingForm]").submit(function(){
      var cinemaNoComp=$("#cinemaSelect").val();
      var startDateComp=$("input[name=startDate]").val();
      var endDateComp=$("input[name=endDate]").val();
      if(cinemaNoComp==""){
         alert("상영 영화관을 선택하세요!");
         return false;
      }
      if(startDateComp==""){
         alert("상영 시작일을 입력하세요!");
         return false;
      }
      if(endDateComp==""){
         alert("상영 종료일을 입력하세요!");
         return false;
      }
      if(!((startM==endM&&startD<=endD)||startM<endM)){
         alert("상영 시작일은 상영 종료일보다 전에 있어야 합니다!");
         $(this)[0].reset();
         return false;
      }
   });
   /* $("#showingUpdate").click(function(){
      var showingNo =  $(":radio[name=showingCheckBtn]:checked");
      var formId = "updateForm" + showingNo.val();
      var showingTr = "showingTr"+showingNo.val();
      $("#"+formId).html("<tr><td>"
            +"<select class='select' id='showingUpdateCinemaSelect'>"
            +"<option value=''>--영화관 선택--</option>"
            +"<c:forEach items='${requestScope.mContentMap.cinemaList }' var='showingUpdateCinemaVO'>"
            +"<option value='${showingUpdateCinemaVO.cinemaNo }'>${showingUpdateCinemaVO.name }</option>"
            +"</c:forEach>"
            +"</select>"+"</td><td>"
            +"<input type='text' name='' value='"+$("#"+showingTr).children().eq(1).text()+"' size='8'></td><td>"
            +"<input type='text' name='' value='"+$("#"+showingTr).children().eq(2).text()+"' size='8'></td><td>"
            +"<input type='button' id='showingUpdateForm' value='수정'></td></tr>");
   });
   $("#showingUpdate2").on("change", "#showingUpdateCinemaSelect", function(){
      alert($(this).val());
      $.ajax({
         type:"post",
         url:"${initParam.root}admin/checkCinema.do",
         data:"cinemaNo="+$(this).val()+"&movieNo=${requestScope.mContentMap.movieContent.movieNo }",
         success:function(jsonData){
            if(jsonData==true){
               alert("상영 리스트에 선택한 영화관이 존재합니다!");
               $("form[name=writeShowingForm]")[0].reset();
            }
         }
      });
   }); */
   
});
</script>
<h3>상영영화 - 상세정보</h3>
<hr align="left" width="150">
<center>
<form action="${initParam.root }admin/showingWrite.do" method="post" name="writeShowingForm">
<input type="hidden" name="movieVO.movieNo" value="${requestScope.allInfoMap.movieContent.movieNo }">
<table class="movieContent">
   <tr>
      <td colspan="3">상영 정보 등록</td>
   </tr>
   <tr>
      <td rowspan="2">
         <select class="select" name="cinemaVO.cinemaNo" id="cinemaSelect">
            <option value="">--영화관 선택--</option>
            <c:forEach items="${requestScope.allInfoMap.cinemaList }" var="cinemaVO">
               <option value="${cinemaVO.cinemaNo }">${cinemaVO.name }</option>
            </c:forEach>   
         </select>
      </td>
      <td>
         상영 시작일: <input type="text" name="startDate" id="startDatepicker" readonly>
      </td>
      <td rowspan="2">
         <input type="submit" id="writeShowingBtn" value="등록">
      </td>
   </tr>
   <tr>
      <td>
         상영 종료일: <input type="text" name="endDate" id="endDatepicker" readonly>
      </td>
   </tr>   
</table>
</form>
<table class="movieContent">
   <!-- 상영 리스트 -->
   <tr>
      <td colspan="5">상영 리스트</td>
   </tr>
   <tr>
      <td>상영영화</td><td>상영관</td><td>상영 시작일</td><td>상영 종료일</td><td></td>
   </tr>
   <c:forEach items="${requestScope.allInfoMap.showingList }" var="showingVO">
      <tr id="showingTr${showingVO.showingNo }">
         <td>${requestScope.allInfoMap.movieContent.title }</td>      
         <td>${showingVO.cinemaVO.name }</td>
         <td>${showingVO.startDate }</td>
         <td>${showingVO.endDate }</td>
         <td>
            <input type="radio" name="showingCheckBtn" value="${showingVO.showingNo }">
         </td>
      </tr>
   </c:forEach>
   <tr>
      <td colspan="5">
         <input type="button" id="schedule" value="스케줄관리">
         <input type="button" id="showingDelete" value="삭제">
      </td>
   </tr>
</table>
</center>